#include <iostream>
#include <thread>
#include <mutex>
#include <unistd.h>

//thread_local 保证了变量进入每一个线程的时候就是拷贝的结果。意思就是
//每一个线程都是对其存储的变量副本进行操作
class A{
	int a;
	thread_local static int b;
	public:
	A():a(0){}
	void inc(){++b;}
	int get(){return b;}
};

thread_local int A::b=100;

A a;

void inc()
{
	std::cout<<"b is "<<a.get()<<std::endl;
	a.inc();
	std::cout<<"b is "<<a.get()<<std::endl;
}

int get()
{
	return a.get();
}

int main(int argc, char *argv[])
{
	std::thread a(inc);
	sleep(2);
	std::thread b(inc);
	a.join();
	b.join();
	return 0;
}
